<template>
  <div class='equip-statics-container'>
    <el-table :data="tableData.list"
              height="530"
              :header-cell-style="{ background: '#f5f5f5' }"
              style="width: 100%;">
      <el-table-column type="index"
                       align="center"
                       show-overflow-tooltip
                       label="序号">
      </el-table-column>
      <el-table-column prop="projectName"
                       align="center"
                       width="100px"
                       show-overflow-tooltip
                       label="项目名称">
      </el-table-column>
      <el-table-column prop="type"
                       align="center"
                       show-overflow-tooltip
                       label="设备类型">
      </el-table-column>
      <el-table-column prop="No"
                       align="center"
                       show-overflow-tooltip
                       label="设备编号">
      </el-table-column>
      <el-table-column prop="status"
                       align="center"
                       show-overflow-tooltip
                       label="检测状态">
      </el-table-column>
      <el-table-column prop="num"
                       align="center"
                       show-overflow-tooltip
                       label="预警次数">
      </el-table-column>
      <el-table-column prop="num1"
                       align="center"
                       show-overflow-tooltip
                       label="报警次数">
      </el-table-column>
      <!-- <el-table-column prop="addr"
                       align="center"
                       show-overflow-tooltip
                       label="位置">
      </el-table-column> -->
    </el-table>
    <el-pagination @current-change="handlePageChange"
                   :current-page="requestParam.page"
                   :page-size="requestParam.per_page"
                   layout="total,sizes,prev, pager, next, jumper"
                   background
                   :total="tableData.total_count"
                   align="center">
    </el-pagination>
  </div>
</template>
<script>
import { standardCodeApi } from '@/services/StandardCode'

export default {
  data () {
    return {

      project_id: '356',
      company_id: '22',
      requestParam: {
        page: 1,
        page_size: 10
      },
      tableData: {
        list: [],
        total_count: 0
      },
    }
  },
  props: {
    projectId: {

    }
  },
  watch: {
    projectId: {
      handler (newval) {
        this.project_id = newval
        this.getEquipData()
      },
      deep: true
    }
  },
  methods: {
    handlePageChange (page) {
      this.requestParam.page = page
      this.getEquipData()
    },
    // 获取机械设备数据
    getEquipData () {
      standardCodeApi.getScreenData({
        data: {
          index_no: 'mechanicalEquipment',
          project_id: this.project_id,
          // project_id: '',
          is_mock: 0,
          company_id: this.company_id,
          // company_id: '1',
          org_no: '',
          conditions: [],
          is_page: 1,
          page: this.requestParam.page,
          page_size: this.requestParam.page_size,
          indexs: [
            {
              index_field: 'dim1'
            },
            {
              index_field: 'index1'
            },
            {
              index_field: 'index2'
            },
            {
              index_field: 'index3'
            },
            {
              index_field: 'index4'
            },
            {
              index_field: "index4",
              index_operation: "sum(?)",
              ais: "index4"
            },
            {
              index_field: 'index5'
            },
            {
              index_field: "index5",
              index_operation: "sum(?)",
              ais: "index5"
            },
            {
              index_field: 'index6'
            },
            {
              index_field: 'index7'
            }
          ],
          dims: [
            {
              dim_field: "index2"
            },
            // {
            //   dim_field: "index7"
            // }
          ]
        }
      }).then(res => {
        if (res.code === 0) {
          if (res.data.total_count > 0) {
            let data = res.data.data.indexs.y
            let len = data.items.index1.data.length
            let index1 = data.items.index1.data
            let index2 = data.items.index2.data
            let index3 = data.items.index3.data
            let index4 = data.items.index4.data
            let index5 = data.items.index5.data
            let index6 = data.items.index6.data
            let index7 = data.items.index7.data
            let list = []
            for (let i = 0; i < len; i++) {
              let temp = {
                type: index1[i],
                No: index2[i],
                status: index3[i],
                num: index4[i],
                num1: index5[i],
                addr: index6[i],
                projectName: index7[i]
              }
              list.push(temp)
            }
            this.tableData.list = list
            this.tableData.total_count = res.data.total_count
          } else {
            this.tableData.list = []
            this.tableData.total_count = 0
          }

        }
      })
    }
  },
  created () {
    this.project_id = this.projectId
    this.company_id = window.localStorage.getItem('comp_id')
    this.getEquipData()
  },
  mounted () {
  }
}
</script>
<style scoped lang='scss'>
.equip-statics-container {
}
</style>